
<table class="table table-condensed table-bordered table-striped table-hover">
    <thead>
       <th>标题</th>
       <th>发表日期</th>
       <th>分类</th>
       <th>顺序</th>
       <th>管理</th>
    </thead>
    <tbody>
    <% for(var i = 0; i < beans.length; i++) { %>

    <tr>
       <td>

           <%= beans[i].name%>

       </td>
       <td><%=moment(beans[i].createDate,"YYYY-MM-DD HH:mm:ss") %></td>
       <td><%= beans[i].articlec.name %></td>
       <td>
           <input id="<%=beans[i]._id%>_sort" type="text" style="width: 50px;"
                  value="<%=beans[i].sort?beans[i].sort:0%>">
       </td>
        <td>
           <%- link_to('修改','/article/findone/'+beans[i]._id)%>
           <div class="btn-group">
           <%- link_to("预览","/article/preview/"+beans[i]._id, {'class':'btn btn-info btn-xs'} )%>
           <button type="button" class="btn btn-success btn-xs"
                    onClick="doHome('<%=beans[i]._id%>',event)">顺序</button>
           <button type="button" class="btn btn-primary btn-xs"
                    onClick="doArea('<%=beans[i]._id%>',event)">

               <%=(beans[i].area && beans[i].area=='A')?'已':''%>推荐

           </button>
           </div>

            <button type="button" class="btn btn-danger btn-xs"
                    onClick="doRemove('<%=beans[i]._id%>',event)">删除</button>


        </td>
    </tr>

    <% } %>
   </tbody>
    <tfoot>
      <tr>

        <td colspan="5">
            <%-pagination%>
        </td>

      </tr>

    </tfoot>
</table>
<script>
    var arcid= '<%=query['articlec.id']%>';

    log("分类编号 :"+arcid);
    $(function(){

        $(document.body).off("click","ul.pagination li a");
        $(document.body).on("click","ul.pagination li a",function(event){
            var link = $(event.target).attr('link');
            if(!link) return true;
            $("#dataTable").load(link+"?layout=0",{'articlec.id':arcid});
        });

        $("#hrefValid").unbind('click');
        $("#hrefValid").bind('click',hrefValid);
        $("#playCtrl").unbind();
        $("#playCtrl").bind('click',playCtrl);


    })

    function doRemove(id,event){
        $.post('/article/remove/'+id,function(result){
            var parent = $(event.target).parent("td").parent("tr");
            parent.remove();
            info("删除成功!");
        });
    }

    function doHome(id,event){
        var sval  = $("#"+id+"_sort").val();
        if(isNaN(sval)){
            info(sval+'不是数字');
            return ;
        }
        doUpdateProp(id,'sort',sval);
    }

    function doArea(id,event){
        doUpdateProp(id,'area','A');
    }

    function doUpdateProp(id,name,value){
        var pobj = {};
        pobj[name] = value;
        $.post('/article/update/'+id,pobj,function(rst){
            log(rst);
            info("属性设置成功");
        });
    }

    function doUpdateArcProp(id,name,value){
        var pobj = {};
        pobj[name] = value;
        $.post('/articlec/update/'+id,pobj,function(rst){
            log(rst);
            info("属性设置成功");
        });
    }

    function hrefValid(event){
        var valid = $(event.target).prop('checked');
        doUpdateArcProp(arcid,'linkvalid',valid);
    }

    function playCtrl(event){
        var valid = $(event.target).prop('checked');
        doUpdateArcProp(arcid,'playctrl',valid);
    }

</script>